<template>
  <div v-if="visible" class="modal-backdrop">
    <div class="modal-content">
      <div class="modal-header">
        <h3>{{ title }}</h3>
      </div>
      <div class="modal-body">
        <slot></slot>
        
        <!-- 上传进度条 -->
        <div v-if="showProgress" class="progress-container">
          <div class="progress-bar" :style="{ width: progress + '%' }"></div>
          <span class="progress-text">{{ progress }}%</span>
        </div>
        
        <!-- 上传结果状态 -->
        <div v-if="status" class="status-message">
          <i :class="statusIcon"></i> {{ status }}
        </div>
      </div>
      <div class="modal-footer">
        <slot name="footer">
          <button class="modal-btn" @click="closeModal">关闭</button>
        </slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

const props = defineProps({
  visible: Boolean,
  title: String,
  progress: Number,
  status: String,
  showProgress: Boolean
})

const emit = defineEmits(['update:visible'])

const closeModal = () => {
  emit('update:visible', false)
}

// 状态图标计算
const statusIcon = computed(() => {
  if (props.status && props.status.includes('成功')) return 'fa fa-check-circle text-green'
  if (props.status && props.status.includes('失败')) return 'fa fa-times-circle text-red'
  return 'fa fa-info-circle text-blue'
})
</script>

<style scoped>
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  width: 400px;
  max-width: 90%;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid #eee;
}

.modal-btn {
  padding: 8px 16px;
  background-color: #4caf50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.modal-btn:hover {
  background-color: #45a049;
}

.progress-container {
  height: 12px;
  background-color: #f3f3f3;
  border-radius: 6px;
  margin: 16px 0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: #4caf50;
  transition: width 0.3s ease;
}

.progress-text {
  display: block;
  text-align: center;
  margin-top: 8px;
  font-size: 14px;
  color: #666;
}

.status-message {
  display: flex;
  align-items: center;
  margin: 16px 0;
  font-size: 16px;
}

.status-message i {
  margin-right: 8px;
  font-size: 18px;
}

.text-green { color: #4caf50; }
.text-red { color: #f44336; }
.text-blue { color: #2196f3; }
</style>
